#ifndef _DESKTOP_DATA_H
#define _DESKTOP_DATA_H

#include "../../../include/common.h"
#include "../../../include/public/public.h"
#include "stdint.h"

typedef struct
{
    // socket
    int s;
    // 接收缓存
    uint8_t buf[256];
    // 接收数据的长度，0、-1时无效
    int len;
    // 开启调试
    int debug;

    // cfg_pu_t *pu;
    // cfg_su_t *su;
    // int slave;

    rt_slist_t slist;

} tcps_t;

static const char *timezone_Table[] = {
    "/usr/share/zoneinfo/Pacific/Fiji",           //-12
    "/usr/share/zoneinfo/Pacific/Pago_Pago",      //-11
    "/usr/share/zoneinfo/America/Adak",           //-10
    "/usr/share/zoneinfo/America/Anchorage",      //-9
    "/usr/share/zoneinfo/America/Los_Angeles",    //-8
    "/usr/share/zoneinfo/America/Denver",         //-7
    "/usr/share/zoneinfo/America/Chicago",        //-6
    "/usr/share/zoneinfo/America/New_York",       //-5
    "/usr/share/zoneinfo/America/Halifax",        //-4
    "/usr/share/zoneinfo/America/Sao_Paulo",      //-3
    "/usr/share/zoneinfo/Atlantic/South_Georgia", //-2
    "/usr/share/zoneinfo/Atlantic/Azores",        //-1
    "/usr/share/zoneinfo/Europe/London",          // 0
    "/usr/share/zoneinfo/Europe/Amsterdam",       // 1
    "/usr/share/zoneinfo/Asia/Jerusalem",         // 2
    "/usr/share/zoneinfo/Europe/Moscow",          // 3
    "/usr/share/zoneinfo/Asia/Muscat",            // 4
    "/usr/share/zoneinfo/Asia/Karachi",           // 5
    "/usr/share/zoneinfo/Asia/Dhaka",             // 6
    "/usr/share/zoneinfo/Asia/Ho_Chi_Minh",       // 7
    "/usr/share/zoneinfo/Asia/Shanghai",          // 8
    "/usr/share/zoneinfo/Asia/Tokyo",             // 9
    "/usr/share/zoneinfo/Australia/Melbourne",    // 10
    "/usr/share/zoneinfo/Pacific/Guadalcanal",    // 11
    "/usr/share/zoneinfo/Pacific/Fiji"            // 12
};

int get_local_mac(const char *if_name, char *local_mac);
int set_local_mac(const char *if_name, char *local_mac);
extern void desktop_run(cfg_pu_t *pu);
// extern void desktop_udp_run(cfg_pu_t *pu);

static int send_heart(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int get_time(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int set_time(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg);
static int get_timezone(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int set_timezone(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg);
static int get_macaddr(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int set_macaddr(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg);
static int get_sn(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int set_sn(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg);
static int get_devtype(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int set_devtype(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg);
static int enter_test_mode(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int exit_test_mode(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int set_do(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msgStr);
static int get_dio_ai(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int get_file_info(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int reply_file_cmd0(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg, char *filename);
static int reply_file_cmd4(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg, char *filename);
static int reply_file_data(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg, char *filename);
static int get_topo(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int recv_file_data(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg, char *filename);
static int sys_reboot(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int get_net_state(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int get_dev_status(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int get_collect_state(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
static int get_dev_data(cfg_pu_t *pu, tcps_t *ctx, uint8_t *req, int nlen, uint8_t *msg);
static int get_trans_state(cfg_pu_t *pu, tcps_t *ctx, uint8_t *msg);
extern int tcps_write(cfg_pu_t *pu, tcps_t *ctx, uint8_t *buf, int len);
static int handle(cfg_pu_t *pu, int connfd);

#endif